﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;

namespace Pixysoft.Framework.Verifications
{
    /// <summary>
    /// 一个暴露在外部的合同类
    /// </summary>
    public class Contract
    {
        /// <summary>
        /// 合同的约束
        /// </summary>
        [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Property, AllowMultiple = false)]
        public class ConstraintAttribute : Attribute, IComparable<ConstraintAttribute>
        {
            long contractId;

            string contractName;

            string constraint = null;

            private ConstraintAttribute()
            {
            }

            public ConstraintAttribute(string constraint)
            {
                this.constraint = constraint;
            }

            public ConstraintAttribute(long contractId, string constraint)
            {
                this.contractId = contractId;
                this.constraint = constraint;
            }

            public ConstraintAttribute(long contractId, string contractName, string constraint)
            {
                this.contractId = contractId;
                this.contractName = contractName;
                this.constraint = constraint;
            }

            /// <summary>
            /// 表示合同里面某项约束的标识
            /// </summary>
            public long ContractId
            {
                get { return contractId; }
                internal set { contractId = value; }
            }

            /// <summary>
            /// 合同名字
            /// </summary>
            public string ContractName
            {
                get { return contractName; }
                internal set { contractName = value; }
            }

            /// <summary>
            /// 约束内容
            /// </summary>
            public string Constraint
            {
                get { return constraint; }
                internal set { constraint = value; }
            }

            public override string ToString()
            {
                return string.Format("contractid={0}, contractname={1},constraint={2}", contractId, ContractName, Constraint);
            }

            #region IComparable<ConstraintAttribute> 成员

            public int CompareTo(ConstraintAttribute other)
            {
                if (this.contractId > other.contractId)
                    return 1;

                else if (this.contractId == other.contractId)
                    return 0;

                else
                    return -1;
            }

            #endregion
        }

        /// <summary>
        /// 合同中不可抗力的描述，例如异常
        /// </summary>
        [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Property, AllowMultiple = false)]
        public class ForceMajeureAttribute : Attribute, IComparable<ForceMajeureAttribute>
        {
            long contractId;

            string contractName;

            string constraint = null;

            private ForceMajeureAttribute()
            {
            }

            public ForceMajeureAttribute(string constraint)
            {
                this.constraint = constraint;
            }

            public ForceMajeureAttribute(long contractId, string constraint)
            {
                this.contractId = contractId;
                this.constraint = constraint;
            }

            public ForceMajeureAttribute(long contractId, string contractName, string constraint)
            {
                this.contractId = contractId;
                this.contractName = contractName;
                this.constraint = constraint;
            }

            /// <summary>
            /// 表示合同里面某项约束的标识
            /// </summary>
            public long ContractId
            {
                get { return contractId; }
                internal set { contractId = value; }
            }

            /// <summary>
            /// 合同名字
            /// </summary>
            public string ContractName
            {
                get { return contractName; }
                internal set { contractName = value; }
            }

            /// <summary>
            /// 约束内容
            /// </summary>
            public string Constraint
            {
                get { return constraint; }
                internal set { constraint = value; }
            }

            #region IComparable<MajeureAttribute> 成员

            public int CompareTo(ForceMajeureAttribute other)
            {
                if (this.contractId > other.contractId)
                    return 1;

                else if (this.contractId == other.contractId)
                    return 0;

                else
                    return -1;
            }

            #endregion
        }

        /// <summary>
        /// 合同的承诺
        /// </summary>
        [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Property, AllowMultiple = true)]
        public class CommitmentAttribute : Attribute, IComparable<CommitmentAttribute>
        {
            long commitId;

            long contractId;

            string commitment = null;

            /// <summary>
            /// 不支持
            /// </summary>
            private CommitmentAttribute()
            {
            }

            /// <summary>
            /// 任意的commitment
            /// </summary>
            /// <param name="commitment"></param>
            public CommitmentAttribute(string commitment)
            {
                this.commitment = commitment;
            }

            /// <summary>
            /// 指定了commitid
            /// </summary>
            /// <param name="commitment"></param>
            public CommitmentAttribute(long contractId)
            {
                this.contractId = contractId;
            }

            /// <summary>
            /// 指定了contractid
            /// </summary>
            /// <param name="contractId"></param>
            /// <param name="commitment"></param>
            public CommitmentAttribute(long contractId, string commitment)
            {
                this.contractId = contractId;
                this.commitment = commitment;
            }

            /// <summary>
            /// 指定了commitid/contractid
            /// </summary>
            /// <param name="conmmitId"></param>
            /// <param name="contractId"></param>
            /// <param name="commitment"></param>
            public CommitmentAttribute(long conmmitId, long contractId, string commitment)
            {
                this.commitId = conmmitId;
                this.contractId = contractId;
                this.commitment = commitment;
            }

            /// <summary>
            /// 合同承诺的id
            /// </summary>
            public long CommitId
            {
                get { return commitId; }
                internal set { commitId = value; }
            }

            /// <summary>
            /// 合同所承诺的约束的id
            /// </summary>
            public long ContractId
            {
                get { return contractId; }
                internal set { contractId = value; }
            }

            /// <summary>
            /// 承诺内容
            /// </summary>
            public string Commitment
            {
                get { return commitment; }
                internal set { commitment = value; }
            }

            #region IComparable<ConstraintAttribute> 成员

            public int CompareTo(CommitmentAttribute other)
            {
                if (this.commitId > other.commitId)
                    return 1;

                else if (this.commitId == other.commitId)
                    return 0;

                else
                    return -1;
            }

            #endregion
        }

        /// <summary>
        /// 合同的履行部分 是承诺履行的部分
        /// </summary>
        [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Property, AllowMultiple = true)]
        public class FulfillmentAttribute : Attribute, IComparable<FulfillmentAttribute>
        {
            long commitmentId;

            string fulfillment = null;

            private FulfillmentAttribute()
            {
            }

            public FulfillmentAttribute(long commitmentId)
            {
                this.commitmentId = commitmentId;
            }

            public FulfillmentAttribute(long commitmentId, string fulfillment)
            {
                this.commitmentId = commitmentId;
                this.fulfillment = fulfillment;
            }

            public long CommitmentId
            {
                get { return commitmentId; }
                internal set { commitmentId = value; }
            }

            public string Fulfillment
            {
                get { return fulfillment; }
                internal set { fulfillment = value; }
            }

            #region IComparable<FulfillmentAttribute> 成员

            public int CompareTo(FulfillmentAttribute other)
            {
                if (this.commitmentId > other.commitmentId)
                    return 1;

                else if (this.commitmentId == other.commitmentId)
                    return 0;

                else
                    return -1;
            }

            #endregion
        }

        /// <summary>
        /// 对不可抗力的拯救
        /// </summary>
        [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Property, AllowMultiple = false)]
        public class RescureAttribute : Attribute
        {
            long rescureId;

            long forceMajeureId;

            string rescureText = null;

            private RescureAttribute()
            {
            }

            public RescureAttribute(long forceMajeureId)
            {
                this.forceMajeureId = forceMajeureId;
            }

            public RescureAttribute(long forceMajeureId, string rescureText)
            {
                this.forceMajeureId = forceMajeureId;
                this.rescureText = rescureText;
            }

            public RescureAttribute(long rescureId, long forceMajeureId, string rescureText)
            {
                this.rescureId = rescureId;
                this.forceMajeureId = forceMajeureId;
                this.rescureText = rescureText;
            }

            public long RescureId
            {
                get { return rescureId; }
                internal set { rescureId = value; }
            }

            public long ForceMajeureId
            {
                get { return forceMajeureId; }
                internal set { forceMajeureId = value; }
            }

            public string RescureText
            {
                get { return rescureText; }
                internal set { rescureText = value; }
            }


        }
    }
}
